<?php if (!defined('BASEPATH')) exit ('No direct script access allowed');
class Member extends CI_Controller
{
	function __construct()
	{
	parent::__construct();
		$this->load->library('access');
	}
	function index()
	{
		$this->access->logout();
		$this->login();
	}
	function login()
	{
		$this->load->library('form_validation');
		$this->load->helper(array('form','url'));

		//$this->form_validation->set_rules('username', 'Username', 'trim|required|strip_tags');
		//$this->form_validation->set_rules('password', 'Password', 'trim|required');
		$this->form_validation->set_rules('token', 'token', 'callback_check_login');
		$data['notif'] = '';
		//$this->output->eneble_profiler(1);
		if($this->form_validation->run() == FALSE)
		{
			$this->load->view('login');
		}
		else
		{
			redirect('data_gudang');
		}
	}
	function logout()
	{
		$this->access->logout();
		redirect('member/login');
	}
	function check_login()
	{
		$username = $this->input->post('username', TRUE);
		$password = $this->input->post('password', TRUE);
		$login = $this->access->login($username, $password);
		if($login)
		{
			return TRUE;
		}
		else
		{
			$this->form_validation->set_message('check_login', 'Username atau password anda salah.');
			return FALSE;
		}
	}
}